home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / tcpip / amiga / asrc29p.lha / axlink.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  3.4 KB  |  194 lines

  1. #include <ctype.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "iface.h"
  5. #include "ax25.h"
  6. #include "ip.h"
  7. #include "timer.h"
  8. #include "lapb.h"
  9.  
  10. #define iscallsign(c) ((isupper(c)) || (isdigit(c)) || (c =='\x20'))
  11. int axheard_filter_flag = AXHEARD_PASS;
  12.  
  13. static struct lq *al_create __ARGS((struct iface *ifp,char *addr));
  14. struct lq *al_lookup __ARGS((struct iface *ifp,char *addr,int sort));
  15. static struct ld *ad_lookup __ARGS((struct iface *ifp,char *addr,int sort));
  16. static struct ld *ad_create __ARGS((struct iface *ifp,char *addr));
  17.  
  18. struct ld *Ld;
  19. struct lq *Lq;
  20.  
  21. /* Log the source address of an incoming packet */
  22. void logsrc(ifp,addr,ctl)
  23. struct iface *ifp;
  24. char *addr;
  25. char ctl;
  26. {
  27.     register struct lq *lp;
  28.     int16 type;
  29.  
  30.     if(addreq(addr,ifp->hwaddr))
  31.         return;    /* Don't log our own packets if we hear them */
  32.  
  33.     if(axheard_filter_flag & AXHEARD_NOSRC)
  34.         return;
  35.     {
  36.         register unsigned char c;
  37.         register int i = 0;
  38.         while(i < AXALEN-1){
  39.             c = *(addr+i);
  40.             c >>= 1;
  41.             if(!iscallsign(c))
  42.                 return;
  43.             i++;
  44.         }
  45.     }
  46.     
  47.     if((lp = al_lookup(ifp,addr,1)) == NULLLQ)
  48.          if((lp = al_create(ifp,addr)) == NULLLQ)
  49.             return;
  50.     type = ftype(ctl);
  51.  
  52.     switch(uchar(type)){
  53.     case I:
  54.         lp->i++;
  55.         break;
  56.     case SABM:
  57.         lp->sabm++;
  58.         break;
  59.     case DISC:
  60.         lp->disc++;
  61.         break;
  62.     case DM:
  63.         lp->dm++;
  64.         break;
  65.     case UA:
  66.         lp->ua++;
  67.         break;
  68.     case RR:
  69.         lp->rr++;
  70.         break;
  71.     case RNR:
  72.         lp->rnr++;
  73.         break;
  74.     case REJ:
  75.         lp->rej++;
  76.         break;
  77.     case FRMR:
  78.         lp->frmr++;
  79.         break;
  80.     case UI:
  81.         lp->ui++;
  82.         break;
  83.     default:
  84.         lp->invalid++;
  85.         break;
  86.     }
  87.  
  88.     lp->currxcnt++;
  89.     lp->time = Clock;
  90. }
  91. /* Log the destination address of an incoming packet */
  92. void logdest(ifp,addr)
  93. struct iface *ifp;
  94. char *addr;
  95. {
  96.     register struct ld *lp;
  97.  
  98.     if(axheard_filter_flag & AXHEARD_NODST)
  99.         return;
  100.     {
  101.         register unsigned char c;
  102.         register int i = 0;
  103.         while(i < AXALEN-1){
  104.             c = *(addr+i);
  105.             c >>= 1;
  106.             if(!iscallsign(c))
  107.                 return;
  108.             i++;
  109.         }
  110.     }
  111.     
  112.     if((lp = ad_lookup(ifp,addr,1)) == NULLLD)
  113.         if((lp = ad_create(ifp,addr)) == NULLLD)
  114.             return;
  115.     lp->currxcnt++;
  116.     lp->time = Clock;
  117. }
  118.  
  119. struct lq *al_lookup(ifp,addr,sort)
  120. struct iface *ifp;
  121. char *addr;
  122. int sort;
  123. {
  124.     register struct lq *lp;
  125.     struct lq *lplast = NULLLQ;
  126.  
  127.     for(lp = Lq;lp != NULLLQ;lplast = lp,lp = lp->next){
  128.         if(addreq(lp->addr,addr) && lp->iface == ifp){
  129.             if(sort && lplast != NULLLQ){
  130.                 /* Move entry to top of list */
  131.                 lplast->next = lp->next;
  132.                 lp->next = Lq;
  133.                 Lq = lp;
  134.             }
  135.             return lp;
  136.         }
  137.     }
  138.     return NULLLQ;
  139. }
  140.  
  141. /* Create a new entry in the AX.25 link table */
  142. static struct lq *al_create(ifp,addr)
  143. struct iface *ifp;
  144. char *addr;
  145. {
  146.     register struct lq *lp;
  147.  
  148.     lp = (struct lq *)callocw(1,sizeof(struct lq));
  149.     memcpy(lp->addr,addr,AXALEN);
  150.     lp->next = Lq;
  151.     Lq = lp;
  152.     lp->iface = ifp;
  153.  
  154.     return lp;
  155. }
  156. /* Look up an entry in the destination database */
  157. static struct ld *ad_lookup(ifp,addr,sort)
  158. struct iface *ifp;
  159. char *addr;
  160. int sort;
  161. {
  162.     register struct ld *lp;
  163.     struct ld *lplast = NULLLD;
  164.  
  165.     for(lp = Ld;lp != NULLLD;lplast = lp,lp = lp->next){
  166.         if((lp->iface == ifp) && addreq(lp->addr,addr)){
  167.             if(sort && lplast != NULLLD){
  168.                 /* Move entry to top of list */
  169.                 lplast->next = lp->next;
  170.                 lp->next = Ld;
  171.                 Ld = lp;
  172.             }
  173.             return lp;
  174.         }
  175.     }
  176.     return NULLLD;
  177. }
  178. /* Create a new entry in the destination database */
  179. static struct ld *ad_create(ifp,addr)
  180. struct iface *ifp;
  181. char *addr;
  182. {
  183.     register struct ld *lp;
  184.  
  185.     lp = (struct ld *)callocw(1,sizeof(struct ld));
  186.     memcpy(lp->addr,addr,AXALEN);
  187.     lp->next = Ld;
  188.     Ld = lp;
  189.     lp->iface = ifp;
  190.  
  191.     return lp;
  192. }
  193.  
  194.